﻿

namespace Mulala.Cavan.Domain.MainBoundedContext.MulalaModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Core.Persistent;
    using Mulala.Cavan.Domain.MainBoundedContext.AttachmentModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Core.MyLinq;

    public class AttachmentSpecification : ISpecification<Attachment, AttachmentSearch>
    {
        public AttachmentSpecification()
        {
            this.SearchParams = new AttachmentSearch();
        }

        public AttachmentSearch SearchParams
        {
            get;
            set;
        }

        public System.Linq.Expressions.Expression<Func<Attachment, bool>> Expression
        {
            get
            {
                IQueryBuilder<Attachment> queryBuilder = QueryBuilder.Create<Attachment>();

                if (null != SearchParams)
                {
                    if (SearchParams.Group != null)
                    {
                        queryBuilder = queryBuilder.Equals(a => (int)a.AttachmentGroup, SearchParams.Group.GetHashCode());
                    }
                    if (SearchParams.OwnerID > 0)
                    {
                        queryBuilder = queryBuilder.Equals(a => a.OwnerID, SearchParams.OwnerID);
                    }
                }

                return queryBuilder.Expression.Expand();
            }
        }
    }
}
